const
  NMAX = 100;

var
  a: array[1..NMAX] of integer;
  n, i, j, ans, count, tmp: integer;

begin
  read(n);
  for i := 1 to n do
    read(a[i]);
  ans := 0;
  for i := 1 to n do 
    if (a[i] > 0) and (a[i]<>i) then 
    begin
      count := 2;
      j := i;
      while a[j] <> i do
      begin
        inc (count);
        tmp := j;
        j := a[j];
        a[tmp] := 0;
      end;
      a[j] := 0;
      ans := ans + count;
    end;
  writeln(ans);
end.
